package com.ravi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ravi.dao.PatientQueueInfoDAO;
import com.ravi.entity.PatientQueueInfo;
import com.ravi.exception.CheckSystemException;
import com.ravi.exception.ErrorCode;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PatientQueueInfoService {

	@Autowired
	private PatientQueueInfoDAO patientQueueInfoDAO;

	public PatientQueueInfo getPatientInfoById(Integer patientId) {
		PatientQueueInfo ret = patientQueueInfoDAO.selectPatientQueueInfoByPatientId(patientId);
		if (ObjectUtils.isEmpty(ret)) {
			throw new CheckSystemException("查询不到此人信息!", ErrorCode.PATIENT_NOT_FOUND);
		}else {
			return ret;
		}
	}

	public int getPatientTotal() {
		List<PatientQueueInfo> patientQueueInfoList = patientQueueInfoDAO.getAll();
		return patientQueueInfoList.size();
	}

	public List<PatientQueueInfo> getPatientLimitList(int pageNum, int pageSize) {
		int offset = (pageNum - 1) * pageSize;
		return patientQueueInfoDAO.getPatientQueueInfoList(offset, pageSize);
	}
	/**
	 * 分页查询患者
	 * @param pageNum 当前页，从1开始
	 * @param pageSize 当前页大小
	 * @return PageInfo<PatientQueueInfo>
	 */
	public PageInfo<PatientQueueInfo> getPatientQueueInfoList(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize, "register_time");
		List<PatientQueueInfo> infoList = patientQueueInfoDAO.getAll();
		return new PageInfo<>(infoList);
	}
}
